<?php


/**
 * Greendizer sales order invoices tab
 *
 * @author      Youssef El Bied <youssef@greendizer.com>
 */
class Greendizer_Module_Block_Tab extends Mage_Adminhtml_Block_Sales_Order_View_Tab_Invoices
{
    protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel($this->_getCollectionClass())
            ->join('sales/invoice', '`sales/invoice`.entity_id=`main_table`.entity_id', 'sent_to_greendizer')
            ->addAttributeToFilter('`main_table`.order_id', $this->getOrder()->getId())
            ->addFieldToSelect('entity_id')
            ->addFieldToSelect('created_at')
            ->addFieldToSelect('order_id')
            ->addFieldToSelect('increment_id')
            ->addFieldToSelect('state')
            ->addFieldToSelect('grand_total')
            ->addFieldToSelect('base_grand_total')
            ->addFieldToSelect('store_currency_code')
            ->addFieldToSelect('base_currency_code')
            ->addFieldToSelect('order_currency_code')
            ->addFieldToSelect('billing_name')
        ;
        $this->setCollection($collection);
        return Mage_Adminhtml_Block_Widget_Grid::_prepareCollection();
    }

    protected function _prepareColumns()
    {
        parent::_prepareColumns();

        $this->addColumn('action',
            array(
                'header'    => Mage::helper('sales')->__('Action'),
                'type'      => 'action',
                'getter'    => 'getId',
                'actions'   => array(
                    array(
                        'caption' => Mage::helper('sales')->__('View'),
                        'url'     => array('base'=>'*/sales_invoice/view'),
                        'field'   => 'invoice_id'
                    )
                ),
                'filter'    => false,
                'sortable'  => false,
                'is_system' => true,
                'renderer'	=> new Greendizer_Module_Block_Renderer()
        ));
    }

    public function getRowUrl($row)
    {
        return '';
    }
}
